package com.android.cl.coludtf.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.android.cl.coludtf.R;
import com.android.cl.coludtf.activity.base.BaseFragment;
import com.android.cl.coludtf.activity.webview.Htmlview;
import com.android.cl.coludtf.adapter.WorkTopAdapter;
import com.android.cl.coludtf.model.NinePalaces;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class Worktop extends BaseFragment {
    private static String local = "file:////android_asset/";
    @BindView(R.id.Gv_Item)
    GridView GvItem;
    private List<NinePalaces> dataList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.fragment_worktop, container, false);
        ButterKnife.bind(this, v);
        WorkTopAdapter adapter = new WorkTopAdapter(dataList);
        GvItem.setAdapter(adapter);
        GvItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String url = dataList.get(position).getUrl().trim();
                String title = dataList.get(position).getText();
                Intent intent = new Intent();
                NinePalaces ninePalaces = new NinePalaces();
                ninePalaces.setUrl(url);
                ninePalaces.setText(title);
                intent.putExtra("data", ninePalaces);
                intent.setClass(getActivity(), Htmlview.class);
                startActivity(intent);
            }
        });
        return v;
    }

    void initData() {
        //图标
        int icno[] = {R.mipmap.jgg128
        };
        //图标下的文字
        String name[] = {"JSBridge", "图标2", "图标3", "图标4", "图标5", "图标6", "图标7", "图标8", "图标9", "图标10", "图标11", "图标12", "图标13", "图标14"};
        dataList = new ArrayList<>();
        for (int i = 0; i < name.length; i++) {
            NinePalaces ninePalaces = new NinePalaces();
            ninePalaces.setImg(icno[0]);
            ninePalaces.setText(name[i]);
            ninePalaces.setType(0);
            if (i == 0) {
                ninePalaces.setType(1);
                ninePalaces.setUrl(local + "js-call-native.html");
            } else {
                ninePalaces.setUrl("http://210.12.209.212:10031/stage/sydj-mobile/webcontent/index.html");
            }
            dataList.add(ninePalaces);
        }

    }
}
